<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="../bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="../css/font-awesome.css"/>
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox" >
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl"/>

        <!--饲料入库查询-->
		<div class="page_main">
			<h3>饲料出库管理</h3><span class="add_link"><a href="feedsOutAdd.ftl">新增饲料出库信息></a></span>
			<div class="page_content">
				<h4>饲料出库查询</h4>
				<br /><br />
				<form id="feedsOut_query" method="post" action="FeedsoutAction_getFeedsoutByCondition">
					<!-- <label>疫苗名称</label><input type="text" name="" id="vaccine_name" class="commonInputtext" /> -->
					<label style="width:100px">开始时间</label><input type="text" name="beginTime" id="start_data" class="commonInputtext" /><span></span>
					<label style="width:100px">结束时间</label><input type="text" name="endTime" id="end_data" class="commonInputtext" /><span></span>
					<label style="width:100px">经手人</label><input type="text" name="leadPerson" class="commonInputtext" />
					<input type="submit" value="查询" id="findByvaccineId" style="display: inline-block; margin-left: 30px;" />
					<br />
				</form>
				<div>
					<table id="feedsOut_table" class="table" width="100%">
						<thead>
							<tr>
								<th><input id="checkall" type="checkbox" /></th>
								<th width="150">饲料名称</th>
								<th width="150">饲料类型</th>
								<th width="150">供应商</th>
								<th width="150">领用人</th>
								<th width="150">领用数量</th>
								<th width="150">计量单位</th>
								<th width="150">领用时间</th>
								<th width="150"></th>
							</tr>
						</thead>
						<tbody>
							<tr id="no_data">
								<td width="20"></td>
								<td width="150">暂无数据</td>

							</tr>
						</tbody>
					</table>
				</div>
				<input type="button" id="deleteAllchoice" value="删除所选" style="display: none;" />
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>
			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>

		<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery.form.js"></script>
		<script src="js/google-maps.js" type="text/javascript" charset="utf-8"></script>
		<script src="dialog/js/dialog.js"></script>
		<script src="js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="flatpickr/flatpickr.js">
		</script>
		<script type="text/javascript" charset="UTF-8">
			$(function function_name() {
				//侧边栏初始化
				$(".vertical-nav").verticalnav({
					speed: 400,
					align: "left"
				});

				//时间控制器初始化
				$("#start_data").flatpickr();
				$("#end_data").flatpickr();

				var re_data; //每次传过来的数据

				$("#feedsOut_query").ajaxForm(function(data) {
					console.log(data);
					re_data = data;
					$("#feedsOut_table tbody tr").remove();
					for(var i = 0; i < data.length; i++) {
						var no = i + 1;
						var tb = $("#feedsOut_table tbody");
						var td1 = '<td><input type="checkbox" class="isCheck" value="' + data[i].outStoreId + '"/></td>';
						var td2 = '<td>' + data[i].feedName + '</td>';
						var td3 = '<td>' + data[i].component + '</td>';
						var td4 = '<td>' + data[i].compName + '</td>';
						var td5 = '<td>' + data[i].leadPerson + '</td>';
						var td6 = '<td>' + data[i].outQuantity + '</td>';
						var td7 = '<td>' + data[i].unit + '</td>';
						var td8 = '<td>' + data[i].outTime.slice(0,10) + '</td>';
						var td_last = '<td><input type="button" onclick="updateData(' + i + ')" class="change" value="更改" style="padding:0 5px"/><input type="button" value="删除" onclick="deleteData(' + data[i].outStoreId + ')" style="padding:0 5px" /></td>'
						var tr_add = '<tr id="feedsOut_row' + data[i].outStoreId + '">' + td1 + td2 + td3 + td4 + td5 + td6 + td7 + td8 + td_last + '</tr>'
						tb.append(tr_add);
					}
					$("#no_data").remove();
					goPage(1,4,"feedsOut_table");
					$("#deleteAllchoice").css("display", "block");
				});

				//删除
				function deleteByids(delete_data) {
					console.log(delete_data);
					$.dialog({
						type: 'confirm',
						contentHtml: '<p style:"magrin:0 auto">确认删除？</p>',
						onClickOk: function() {
							$.ajax({
								url: "FeedsoutAction_deleteFeedsOut",
								data: {
									'selectRows': delete_data
								},
								success: function() {
									//弹成功框
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/success.png" alt="删除成功" /><p class="info-text">删除成功</p>',
										autoClose: 2000
									});
									//删除相对应的行
									var chrstr = delete_data.split(",");
									console.log(chrstr);
									console.log($("#feedsOut_row" + chrstr[0]));
									for(i = 0; i < chrstr.length; i++) {
										$("#feedsOut_row" + chrstr[i]).remove();
									}
								}
							});
						}
					});

				}
				deleteData = function(i) {
					var st = i;
					st += ",";
					deleteByids(st);
				}
				$("#deleteAllchoice").click(function() {
					delete_data = get_checkbox_data();
					deleteByids(delete_data);
				});

				function get_checkbox_data() {
					var data_temp = "";
					$("input[class='isCheck']:checked").each(function() { // 遍历选中的checkbox
						data_temp += $(this).val() + ',';
						console.log(data_temp);
					});
					return data_temp;
				}
				
				//更新
				updateData = function(i) {
					var row0 = '<form id="feedsOut_updateform" action="FeedsoutAction_updateFeedsOut" method="post"><ul class="changePage500">'
					var row1 = '<li><label class="labelBeforinput">饲料名称</label><input name="feedName" require class="bigInputtext" readOnly="true" type="text" value="' + re_data[i].feedName + '" /></li>';
					var row2 = '<li><label class="labelBeforinput">领用人</label><input name="leadPerson" data-rule-isChinese="true" require class="bigInputtext" type="text" value="' + re_data[i].leadPerson + '" /></li>';
					var row3 = '<li><label class="labelBeforinput">领用数量</label><input name="outQuantity" data-rule-isIntGtZero="true" require class="bigInputtext" type="text" value="' + re_data[i].outQuantity + '" /></li>';
					var row4 = '<li><label class="labelBeforinput">计量单位</label><input name="unit" require class="bigInputtext" type="text" value="' + re_data[i].unit + '" /></li>';
					var row5 = '<li><label class="labelBeforinput">领用时间</label><input name="outTime" data-date-format="Y-m-d" class="bigInputtext" type="text" value="' + re_data[i].outTime.slice(0,10) + '" /></li></ul>';
					var row6 = '<input type="hidden" name="feeds.feedId" value="' + re_data[i].feedID + '" />';
					var row7 = '<input type="hidden" name="compID" value="' + re_data[i].compID + '" />';
					var row8 = '<input type="hidden" name="areacodeinfor.areaId" value="' + re_data[i].areaID + '" />';
					var row9 = '<input type="hidden" name="outStoreId" value="' + re_data[i].outStoreId + '" />';
					var row10 = '<input type="hidden" name="oldAmount" value="' + re_data[i].outQuantity + '" />';
					var row11 = '<input type="hidden" name="storeman" value="' + re_data[i].storeman + '" />';
					var row12 = '<input type="hidden" name="compName" value="' + re_data[i].compName + '" />';
					var row13 = '<input type="hidden" name="component" value="' + re_data[i].component + '" />';
					var rowLast = '</form>'
					var str = row0 + row1 + row2 + row3 + row4 + row5 + row6 + row7 + row8 + row9 + row10 +row11+row12 + row13 + rowLast;
					//console.log($("#quarantine_table"));

					$.dialog({
						type: 'confirm',
						titleText: '更改数据',
						contentHtml: str,
						onClickOk: function() {
							$("#feedsOut_updateform").ajaxSubmit({
								type: 'post',
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									//弹失败框
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/fail.png" alt="更新失败" /><p class="info-text">更新失败</p>',
										autoClose: 2000
									});
								},
								success: function(data) {
									$.dialog({
									       type : 'info',
									       contentHtml : '<img class="info-icon" src="dialog/images/icon/success.png" alt="更新成功" /><p class="info-text">更新成功</p>',
									       autoClose : 2000
									    });

									console.log(data);
									var row = $("#feedsOut_row" + data.feedsout.outStoreId);
									
									row.find("td").eq(1).text(data.feedsout.feedName);
									row.find("td").eq(2).text(data.feedsout.component);
									row.find("td").eq(3).text(data.feedsout.compName);
									row.find("td").eq(4).text(data.feedsout.leadPerson);
									row.find("td").eq(5).text(data.feedsout.outQuantity);
									row.find("td").eq(6).text(data.feedsout.unit);
									row.find("td").eq(7).text(data.feedsout.outTime.slice(0,10));
									
								}

							});
						}

					});
					//时间控制器
					$("input[name='outTime']").flatpickr();
					$("input[name='temporaryOutDate']").flatpickr();
					
					//表单校验
					
					$("feedsOut_updateform").validate();
				}
			})
		</script>

	</body>

</html>